package com.ks.user.controller;


import com.ks.core.base._ControllerBase;
import com.ks.core.core.Result;
import com.ks.core.dto.SearchCriteriaBase;
import com.ks.user.controller.dto.ApBaseRequest;
import com.ks.user.controller.dto.ApTenantAllowRequest;
import com.ks.user.entity.ApBase;
import com.ks.user.entity.ApTenantAllow;
import com.ks.user.entity.PowerResurce;
import com.ks.user.service.IApBaseService;
import com.ks.user.service.IApTenantAllowService;
import com.ks.user.service.IPowerResurceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 应用基本信息表 前端控制器
 * </p>
 *
 * @author kingdee123
 * @since 2020-12-11
 */
@RestController
@RequestMapping("/sysApBase")
@Api(value = "应用管理模块", description = "应用管理块")
public class ApBaseAdminController extends _ControllerBase {

    @Autowired
    private IApBaseService apBaseService;

    @Autowired
    private IPowerResurceService powerResurceService;

    @Autowired
    private IApTenantAllowService apTenantAllowService;

    @PostMapping("/selectTenant")
    @ApiOperation(value = "查询系统应用清单接口", notes = "查询系统应用清单接口")
    public Object selectTenant(@RequestBody SearchCriteriaBase searchCriteriaBase) {
        Map<String, Object> resultMap = apBaseService.getSysTenantList(getContext(), searchCriteriaBase);
        return Result.success(resultMap);
    }


    @PostMapping("/addApBase")
    @ApiOperation(value = "应用管理模块添加接口", notes = "应用管理模块添加接口")
    public Object addSysApBase(@RequestBody ApBase apBase) {
        int i = apBaseService.addApBase(getContext(), apBase);
        return Result.success(i);
    }

    @PostMapping("/isState")
    @ApiOperation(value = "应用管理模块应用上线下线设置接口", notes = "应用管理模块应用上线下线设置接口")
    public Object isStateSysApBase(@RequestBody ApBase apBase) {
        int i = apBaseService.isState(getContext(), apBase);
        return Result.success(i);
    }

    @PostMapping("/update")
    @ApiOperation(value = "应用管理模块应用信息修改接口", notes = "应用管理模块应用信息修改接口")
    public Object updateSysApBase(@RequestBody ApBase apBase) {
        int i = apBaseService.updateSysApBase(getContext(), apBase);
        return Result.success(i);
    }


    @PostMapping("/addAppMenu")
    @ApiOperation(value = "应用管理模块应用菜单添加接口", notes = "应用管理模块应用菜单添加接口")
    public Object addAppMenu(@RequestBody PowerResurce powerResurce) {
        int i = powerResurceService.addPowerResurce(getContext(), powerResurce);
        return Result.success(i);
    }


    @PostMapping("/selectAppMenu")
    @ApiOperation(value = "应用管理模块应用菜单查询接口", notes = "应用管理模块应用菜单查询接口")
    public Object selectAppMenu(@RequestBody ApBaseRequest  request) {
        Map<String, Object> resultMap = powerResurceService.selectAppMenu(getContext(), request.getId());
        return Result.success(resultMap);
    }

    @PostMapping("/updateAppMenu")
    @ApiOperation(value = "应用管理模块应用菜单修改接口", notes = "应用管理模块应用菜单修改接口")
    public Object updateAppMenu(@RequestBody PowerResurce  powerResurce) {
        int i = powerResurceService.updateRower(getContext(), powerResurce);
        return Result.success(i);
    }


    @PostMapping("/deleteAppMenu")
    @ApiOperation(value = "应用管理模块应用菜单删除接口", notes = "应用管理模块应用菜单删除接口")
    public Object deleteAppMenu(@RequestBody PowerResurce powerResurce) {
        int i = powerResurceService.deleteAppMenu(getContext(), powerResurce);
        return Result.success(i);
    }


    @PostMapping("/appEmpower")
    @ApiOperation(value = "管理模块应用授权接口", notes = "管理模块应用授权接口")
    public Object appEmpower(@RequestBody List<ApBase> apBaseList) {
        int i = apTenantAllowService.appEmpower(getContext(), apBaseList);
        return Result.success(i);
    }

    @PostMapping("/moveEmpower")
    @ApiOperation(value = "管理模块应用授权移除接口", notes = "管理模块应用授权移除接口")
    public Object moveEmpower(@RequestBody List<ApBase> apBaseList) {
        int i = apTenantAllowService.moveEmpower(getContext(), apBaseList);
        return Result.success(i);
    }

    @PostMapping("/selectEmpower")
    @ApiOperation(value = "管理模块应用已授权查询接口", notes = "管理模块应用已授权查询接口")
    public Object selectEmpower(@RequestBody ApTenantAllowRequest request) {
        Map<String, Object> i = apTenantAllowService.selectEmpower(getContext(), request.getTenantId());
        return Result.success(i);
    }
}
